//
//  HNSH_ShopApplyUpLoadCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/4.
//

#import "HNSH_ShopApplyUpLoadCell.h"

@interface HNSH_ShopApplyUpLoadCell ()

/* titleLabel */
@property (nonatomic, strong) UILabel *titleLabel;
/* desLabel */
@property (nonatomic, strong) UILabel *desLabel;
/* lineView */
@property (nonatomic, strong) UIView *lineView;

/* showButton */
@property (nonatomic, strong) UIButton *showButton;
/* addButton */
@property (nonatomic, strong) UIButton *addButton;

/* imgView */
@property (nonatomic, strong) UIImageView *imgView;

@end

@implementation HNSH_ShopApplyUpLoadCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self configView];
    }
    return self;
}

- (void)setImgString:(NSString *)imgString {
    _imgString = imgString;
    if (![imgString isNotBlank]) {
        return;
    }
    self.imgView.hidden = NO;
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:imgString]];
    [self.showButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-118);
    }];
}

- (void)setDesString:(NSString *)desString {
    _desString = desString;
    self.desLabel.text = desString;
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}

- (void)configView {
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.desLabel];
    [self.contentView addSubview:self.lineView];
    [self.contentView addSubview:self.showButton];
    [self.contentView addSubview:self.addButton];
    [self.contentView addSubview:self.imgView];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(16);
        make.left.mas_equalTo(18);
        make.height.mas_equalTo(20);
    }];
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(4);
        make.left.height.mas_equalTo(self.titleLabel);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    [self.showButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(66);
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(88);
        make.height.mas_equalTo(17);
        make.bottom.mas_equalTo(-17).priorityHigh();
    }];
    
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(31);
        make.right.mas_equalTo(-20);
        make.width.mas_equalTo(32);
        make.height.mas_equalTo(32);
    }];
    
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.bottom.mas_equalTo(-14);
        make.width.mas_equalTo(142);
        make.height.mas_equalTo(91);
    }];
    
    WeakSelf(weakSelf);
    [[self.showButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
    }];
    [[self.addButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.addBlock) {
            weakSelf.addBlock(weakSelf);
        }
    }];
}

#pragma mark lazy
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = [UIColor appBlackLabelColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _titleLabel;
}

- (UILabel *)desLabel {
    if (!_desLabel) {
        _desLabel = [[UILabel alloc]init];
        _desLabel.textColor = [UIColor appGrayLabelColor];
        _desLabel.font = [UIFont systemFontOfSize:14];
    }
    return _desLabel;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#EDEDED"];
    }
    return _lineView;
}

- (UIButton *)showButton {
    if (!_showButton) {
        _showButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_showButton setTitle:@"查看示例" forState:UIControlStateNormal];
        [_showButton setTitleColor:[UIColor appGreenColor] forState:UIControlStateNormal];
        _showButton.titleLabel.font = [UIFont systemFontOfSize:12];
        WeakSelf(weakSelf);
        [[_showButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.showBlock) {
                weakSelf.showBlock();
            }
        }];
    }
    return _showButton;
}

- (UIButton *)addButton {
    if (!_addButton) {
        _addButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addButton setImage:[UIImage imageNamed:@"mine_shop_apply_add_zp"] forState:UIControlStateNormal];
    }
    return _addButton;
}

- (UIImageView *)imgView {
    if (!_imgView) {
        _imgView = [[UIImageView alloc]init];
        _imgView.contentMode = UIViewContentModeScaleAspectFill;
        _imgView.hidden = YES;
        _imgView.clipsToBounds = YES;
    }
    return _imgView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
